package fieldmaps;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.vecmath.Point2d;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LinearRing;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.geom.impl.CoordinateArraySequence;

import fieldmaps.exceptions.MapAlgebraException;
import fieldmaps.mapalgebra.ICallbackBinary;

/**
 * FieldMaps!
 *
 */
public class Run {
    public static void main( String[] args ) throws SQLException, IOException {
//    	List<Polygon> cell = dbMap.getCell(new Point(new CoordinateArraySequence(new Coordinate[] {
//    			new Coordinate(179.8433333333334,89.84333333333334)
//    	}), new GeometryFactory()));
//    	
//    	if (cell != null) {
//	    	List<Polygon> neighbors = dbMap.getCellNeighbors(cell.get(0));
//	    	
//	    	for (Polygon neighbor: neighbors) {
//	    		System.out.println(neighbor);
//	    	}
//    	} else {
//    		System.out.println("cell null!");
//    	}
//    	ICallbackBinary callback = new ICallbackBinary() {
//			
//			@Override
//			public String newMapName() {
//				return "NewMapBinary";
//			}
//			
//			@Override
//			public Object doOperation(Object mapPolValue1, Object mapPolValue2) {
//				return (Integer)mapPolValue1 + (Integer)mapPolValue2;
//			}
//		};
//		
//		try {
//			RasterBinaryMapAlgebra mapAlgebra = new RasterBinaryMapAlgebra("Prec0", "NewMapUnary");
//			mapAlgebra.mapOperation(callback);
//			SaveMapToFile sm = new SaveMapToFile("NewMap", "./dataRaster/prec_10m_bil/NewMap");
//			sm.saveMap();
//		} catch (IllegalArgumentException e) {
//			e.printStackTrace();
//		} catch (MapAlgebraException e) {
//			e.printStackTrace();
//		}
    }
    
    private static Polygon createPolygon (Point2d[] points) {
    	List<Coordinate> coordinates = new ArrayList<Coordinate>();
    	for (Point2d point: points) {
			Coordinate coordinate = new Coordinate();
			coordinate.x = Double.valueOf(point.x);
			coordinate.y = Double.valueOf(point.y);
			coordinates.add(coordinate);
		}
		LinearRing linearRing = new LinearRing(new CoordinateArraySequence(coordinates.toArray(new Coordinate[0])), new GeometryFactory());
		return new Polygon(linearRing, null, new GeometryFactory());
    }
}
